#include <stdio.h>
#include <string.h>
int main()
{
    FILE* file = fopen("log.txt", "w");
    if(file == NULL)
    {
        perror("open fail");
        return -1;
    }

    const char* message = "hello world\n";
    fwrite(message, 1, strlen(message), file);//将message写入到文件中
    fclose(file);

    file = fopen("log.txt", "r");
    char buffer[100];
    size_t n = fread(buffer, 1, 100, file);//从文件中读取数据放入到buffer中
    buffer[n] = '\0';
    printf("fread:%s\n",buffer);

    fclose(file);
    return 0;
}
